/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * <p>Project: JavaStudy - Img4
 * <p>Powered by jiangbo On 2023-01-05
 * 20:34:16
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Img4 {
        public static void main(String[] args) throws Exception {
            var w = 600;
            var h = 600;
//此图像模式必须保存为png格式
            var t = BufferedImage.TYPE_INT_ARGB;
            var img = new BufferedImage(w, h, t);
//建立画笔
            var g = img.createGraphics();
//文字线条，抗锯齿，使平滑。
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
                    RenderingHints.VALUE_STROKE_DEFAULT);
//设置颜色为橘黄色
            g.setColor(Color.ORANGE);
//画一个填充矩形作为画布颜色
            g.fillRect(0, 0, w - 1, h - 1);
//线条尺寸 (BasicStroke)
            g.setStroke(new BasicStroke(3.5f));
//设置画笔颜色 Color对象
            g.setColor(Color.RED);
//在x 100 y 100 坐标位置画 210 * 210的正空心圆
            g.drawOval(w / 2 - 105, h / 2 - 105, 210, 210);
//设置画笔为虚线效果，粗细为1.5f
            Stroke dash = new BasicStroke(1.5f, BasicStroke.CAP_BUTT,
                    BasicStroke.JOIN_ROUND, 0f, new float[]{5}, 0f);
            g.setStroke(dash);
//设置画笔颜色
            g.setColor(Color.GREEN);
            g.drawLine(0, h / 2, w, h / 2);
            g.setColor(Color.BLUE);
            g.drawLine(w / 2, 0, w / 2, h);
//设置颜色透明,最后50代表颜色透明度，0完全透明，255不透明
            g.setColor(new Color(255, 0, 255, 100));
//绘制圆角矩形，填充的
            g.fillRoundRect((w - 360) / 2, (h - 360) / 2, 360, 360, 15, 15);
//释放画笔占用的内存资源
            g.dispose();
//png格式，画布透明
            ImageIO.write(img, "png", new File("img4.png"));
//直接打开图像
            Runtime.getRuntime().exec("cmd /k start img4.png");
        }
}


